package qmm.servlet.admin;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import qmm.dao.BaseOrderDao;
import qmm.dao.impl.BaseOrderDaoImpl;
import qmm.entity.BaseOrder;
import qmm.entity.User;
import qmm.servlet.BaseServlet;
@WebServlet("/admin/AdminBaseOrderServlet")
public class AdminBaseOrderServlet extends BaseServlet{
	
	BaseOrderDao dao = new BaseOrderDaoImpl();
	
	public void findAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		int page = Integer.parseInt(request.getParameter("page"));//ҳ
		int size = Integer.parseInt(request.getParameter("limit"));//ÿҳ
		String orderNo = request.getParameter("orderNo");
		
		List<BaseOrder> list = dao.findAll(orderNo, page, size);
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "");
		map.put("count", dao.getCount(orderNo));
		map.put("data", list);
		String json = JSON.toJSONString(map);
		response.getWriter().write(json);
	}
	
	public void send(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		int id = Integer.parseInt(request.getParameter("id"));
		String waybill = request.getParameter("waybill");
		int n = dao.send(id, waybill);
		response.getWriter().write("success");
	}

}
